package com.smi;

import com.smi.service.FileUtil;
import com.smi.service.Memory;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

/**
 * @Author: yesiming
 * @Date: 下午2:24 2018/3/29
 */
public class SettingController implements Initializable {

    @FXML private TextField host;
    @FXML private TextField port;
    @FXML private TextField user;
    @FXML private TextField passwd;

    @FXML private Button saveBt;

    @FXML
    protected void handleSaveButtonAction(ActionEvent event) throws IOException {
        FileUtil.writeToFile(host.getText(),
                port.getText(),
                user.getText(),
                passwd.getText());
        Memory.CONF = FileUtil.readLine();
        Memory.resetUrl();

        Stage stage = (Stage) saveBt.getScene().getWindow();
        stage.close();

    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        host.setText(Memory.CONF[0]);
        port.setText(Memory.CONF[1]);
        user.setText(Memory.CONF[2]);
        passwd.setText(Memory.CONF[3]);
    }
}
